import random

class CourseTest:
    def __init__(self, course, knowledge_point, num_questions, score):
        self.course = course
        self.knowledge_point = knowledge_point
        self.num_questions = num_questions
        self.score = score
        self.test_questions = []
        self.question_types = ["选择题", "判断题", "简答题"]

    def generate_test(self):
        for _ in range(self.num_questions):
            question_type = random.choice(self.question_types)
            if question_type == "选择题":
                question = f"这是一道选择题"
            elif question_type == "判断题":
                question = f"这是一道判断题"
            elif question_type == "简答题":
                question = f"这是一道简答题"
            self.test_questions.append((question_type, question))

    def analyze_test(self):
        print(f"{self.course}课程测试分析：")
        print(f"{self.knowledge_point}知识点考察")
        print(f"试题总数：{self.num_questions}")
        print(f"试题列表：")
        for idx, (question_type, question) in enumerate(self.test_questions, start=1):
            print(f"题目{idx} ({question_type}): {question}")

class TestAnalysis:
    def __init__(self, test_time, test_details, coursetest):
        self.test_time = test_time
        self.test_details = test_details
        self.coursetest = coursetest

    def analyze(self):
        print("测试时间:", self.test_time)
        print("学生姓名:", self.test_details.get("学生姓名"))
        print(f"试卷信息: {self.coursetest.course}期末考试")
        print(        "答题情况:")
        for question_num, answer in self.test_details.get("答题情况").items():
            question_type = self.coursetest.test_questions[int(question_num.split("题目")[1]) - 1][0]
            if question_type == "选择题":
                answer_options = ["A", "B", "C", "D"]
                answer_text = random.choice(answer_options)
            elif question_type == "判断题":
                answer_options = ["对", "错"]
                answer_text = random.choice(answer_options)
            elif question_type == "简答题":
                answer_text = "XXX"
            print(f"题目{question_num} ({question_type}): {answer_text}")
        exam_result = random.randint(0, 100)  # 随机生成考试结果
        correct_rate = exam_result / 100  # 计算正确率
        print("考试结果:", exam_result)
        print("正确率:", correct_rate)

# 创建课程测试对象
test1 = CourseTest(course="数学", knowledge_point="代数", num_questions=5, score=10)
test2 = CourseTest(course="语文", knowledge_point="文言文", num_questions=5, score=10)
# 生成试卷
test1.generate_test()
test2.generate_test()
# 进行测试分析
test1.analyze_test()
test2.analyze_test()

# 假设测试数据
test_time = "2024-06-09"
test_details = {
    "试卷信息": "数学期末考试",
    "学生姓名": "张三",
    "答题情况": {
        "题目1": "A",
        "题目2": "B",
        "题目3": "C",
        "题目4": "对",
        "题目5": "对"
    },
    "考试结果": "90"
}
# 更多测试数据
test_time_2 = "2024-06-10"
test_details_2 = {
    "试卷信息": "语文期末考试",
    "学生姓名": "李四",
    "答题情况": {
        "题目1": "B",
        "题目2": "A",
        "题目3": "D",
        "题目4": "B",
        "题目5": "C"
    },
    "考试结果": "85"
}

# 创建 TestAnalysis 实例
test_analysis = TestAnalysis(test_time, test_details, test1)
test_analysis_2 = TestAnalysis(test_time_2, test_details_2, test2)
# 进行试卷测试分析
test_analysis.analyze()
test_analysis_2.analyze()

# 计算平均分
results = [int(test_details["考试结果"]), int(test_details_2["考试结果"])]
average_score = sum(results) / len(results)
print("平均分:", average_score)